dernier=0;

function UpdateContacts(num)
{
	xhr = getXMLHTTP();
	cli_id = document.getElementById('client'+num).value;
	if (xhr){
		xhr.onreadystatechange = function(){
			if (xhr.readyState == 4) { //data is retrieved from server
				if (xhr.status == 200) { // which reprents ok status
					reponse = xhr.responseText;
					options = reponse.split('££');
					document.getElementById('contact'+num).length = 0;
					for (i = 0; i < options.length; i++)
					{	
						option = options[i].split('£');
						var oOption = document.createElement("OPTION");
						oOption.text=option[2];
						oOption.value=option[0];
						try {
							document.getElementById('contact'+num).add(oOption, null); // standards compliant; doesn't work in IE
						}
						catch(ex) {
							document.getElementById('contact'+num).add(oOption); // IE only
						}				
					}
					
					//document.getElementById('contact'+num).innerHTML=xhr.responseText;
				}
				else
				{ 
					alert("There was a problem while using XMLHTTP:\n");
				}
			}            
		}       
		xhr.open("GET", 'ajax/sel_contact.php?num_participant='+num+'&cli_id='+cli_id, true); //open url using get method
		xhr.send(null);
	}
}

function AjoutParticipant(cli_id){
	xhr = getXMLHTTP();
	if (xhr){
		xhr.onreadystatechange = function(){
			if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					//document.getElementById('participants').innerHTML+=xhr.responseText;
					document.getElementById('participants').innerHTML+=xhr.responseText;
					UpdateContacts(dernier);
				}
				else
				{ 
					alert("There was a problem while using XMLHTTP:\n");
				}
			}            
		}
		dernier = dernier+1;    
		xhr.open("GET", 'ajax/bloc_participant.php?num_participant='+dernier+'&cli_id='+cli_id, true); //open url using get method
		xhr.send(null);
	}
}

function SupprParticipant(num){
	if (num!=0){
		var mynode = document.getElementById('participant'+num);
		var parent = mynode.parentNode;	 
		parent.removeChild(mynode);
	}
}

function AjoutContact(num){
	chaine = new Array();
	j = -1;
	for (i = 0; i < dernier+1; i++){
		if (document.getElementById('client'+i)){			
			chaine.push(document.getElementById('client'+i).value);
			chaine.push(document.getElementById('contact'+i).value);
			j++;
			if (i==num){
				index = j;
			}
		}
	}
	//alert(chaine.join("_"));
	gets = urlget();
	window.location.href='contact.php?id=-1&rap_id='+gets['id']+'&part_num='+index+'&cli_id='+document.getElementById('client'+num).value+'&part_key='+chaine.join("_");  
}
